package com.journey.org.ui.video.recommend

import android.os.Bundle
import com.journey.org.entity.DataRecommend
import com.journey.org.ui.video.broadcast.BroadcastActivity
import com.mvvmhabit.org.base.MultiItemViewModel
import com.mvvmhabit.org.binding.command.BindingAction
import com.mvvmhabit.org.binding.command.BindingCommand
import com.mvvmhabit.org.utils.loadTimeByLong

/**
 * @Date: 2020/11/19 16:46
 * @Author:小妖
 * @Description: 推荐视频 - 标题
 */
class RecommendTodayViewModel(vm: RecommendViewModel, val entity: DataRecommend) :
    MultiItemViewModel<RecommendViewModel>(vm) {


    val showTime = loadTimeByLong(entity.duration.toLong())

    var imageUrl = ""
    var content = ""
    var title = ""

    init {
        if (entity.dataType == "FollowCard") {
            imageUrl = entity.content.data.cover.detail
            content = "#" + entity.content.data.category + " / " + entity.content.data.author.name
            title = entity.content.data.title
        } else {
            imageUrl =entity.cover.detail
            content = "#" + entity.category + " / " + entity.author?.name
            title = entity.title
        }
    }

    val onEnterVideoCommand = BindingCommand<Any>(object : BindingAction {
        override fun call() {
            val bundle = Bundle()
            bundle.putString("type", "recommend")
            if (entity.dataType == "FollowCard") {
                bundle.putString("url", entity.content.data.playUrl)
                bundle.putString("id", entity.content.data.id.toString())
                bundle.putString("time", entity.content.data.releaseTime.toString())
                bundle.putString("title", entity.content.data.title)
                bundle.putString("dec", entity.content.data.description)
                bundle.putString(
                    "content",
                    "# " + entity.content.data.category + " / " + entity.content.data.author.name
                )
            } else{
                bundle.putString("id", entity.id.toString())
                bundle.putString("url", entity.playUrl)
                bundle.putString("time", entity.releaseTime.toString())
                bundle.putString("title", entity.title)
                bundle.putString("dec", entity.description)
                bundle.putString(
                    "content",
                    "# " + entity.category + " / " + entity.author!!.name
                )
            }
            viewModel.startActivity(BroadcastActivity::class.java, bundle)
        }
    })

}